package com.kenliang.netty.rpc.netty;

import com.google.common.reflect.AbstractInvocationHandler;
import com.kenliang.netty.rpc.model.MessageRequest;

import java.lang.reflect.Method;
import java.util.UUID;

/**
 * @author KenLiang
 * @description:
 * @date Created in 4:07 PM 2019/3/21.
 */
public class MessageSendProxy extends AbstractInvocationHandler {
    @Override
    protected Object handleInvocation(Object proxy, Method method, Object[] args) throws Throwable {
        MessageRequest messageRequest = new MessageRequest();
        //todo 这个id有什么用？
        messageRequest.setMessageId(UUID.randomUUID().toString());
        messageRequest.setClassName(method.getDeclaringClass().getName());
        messageRequest.setMethodName(method.getName());
        messageRequest.setTypeParameters(method.getParameterTypes());
        messageRequest.setParametersVal(args);

        MessageSendHandler messageSendHandler = RpcClientLoader.getInstance().getMessageSendHandler();
        messageSendHandler.sendRequest(messageRequest);
        return null;
    }
}
